home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9587 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: dish.news.pipex.net!pipex!dircon!usenet
  2. From: sridgway@dircon.co.uk (Steven Ridgway)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: CALL_BY_VALUE with ARRAYS ?
  5. Date: Mon, 11 Mar 1996 21:57:28 GMT
  6. Organization: Direct Connection
  7. Message-ID: <4i27r6$28m@newsgate.dircon.co.uk>
  8. References: <31442A98.41C6@dkfz-heidelberg.de>
  9. NNTP-Posting-Host: gw4-129.pool.dircon.co.uk
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Ramon Wartala <r.wartala@dkfz-heidelberg.de> wrote:
  13.  
  14. >Hello World,
  15.  
  16.  
  17. >I've a problem which risks to break my nervs.
  18.  
  19.  
  20. >How can I call a function by a pointer, and giving her
  21. >a number of paramters which I don't know before executing ?
  22.  
  23. >Exp. 
  24.  
  25. >Funcion :
  26.  
  27. >   int foo(char a, char b , char c) {}
  28.  
  29.  
  30. >   void main()
  31. >    {
  32. >      int (*ptr)()=foo;
  33. >      /* .... */
  34. >      /* calling my function now ... */
  35. >      (ptr)(a_variable);
  36. >      /* ... while variable is a just a structure of 3 char. long */
  37. >}
  38.  
  39.  
  40. >The problem is, that I can define such a structure (e.g. by char
  41. >a_variable[3]), but if I try to give it to my function foo, the 
  42. >compiler gives naturally only the reference of this 3-byte buffer
  43. >(which is totaly normal) to my function foo.
  44.  
  45. >So my question could be explained with other words :
  46.  
  47. >How can I force the compiler ( gcc for preference) to make a
  48. >call_by_value although with arrays ?
  49.  
  50.  
  51. >Thanks in advane for your help !
  52.  
  53.  
  54. >Jens
  55.  
  56.  
  57. >*** Jens Astor                        *****
  58. >*** jastor@jupiter.rz.fh-heilbronn.de *****
  59. >*** University of Heidelberg, Germany *****
  60.  
  61. Hi,
  62.  
  63. Why do you want to do this at all? Why not define foo to take a void *
  64. as its argument. Then cast this into whatever you want inside foo (ie
  65. an array of chars or whatever).
  66.  
  67. Steven Ridgway (sridgway@dircon.co.uk)
  68.  
  69.  
  70.  
  71.